1. Field of the Invention
The invention relates to software for implementing mathematical functions. Specifically, the invention relates to apparatus, systems, and methods for efficient and reliable computation of results for mathematical functions.
2. Description of the Related Art
Generally, processing systems such as computers and calculators are capable of evaluating a set of general purpose mathematical functions, also referred to herein as math functions. Certain math functions are executed hundreds or thousands of times to perform what appear to a user to be simple operations, such as simple animation. The software libraries that implement the math functions are consequently written for very fast execution using a highly optimized form of assembly language or machine code. Generally, these math functions perform well for a large set of values that can be provided as arguments to the math function.
Math functions are considered to provide results within number sets bounded by negative infinity and positive infinity. Conventional computers, however, have natural limits on the maximum value, minimum value, and type of value that can be represented in the computer. Typically, these limits depend on the hardware and software architecture of the processing system that evaluates the math function. Values that fall outside of these limits are referred to herein as unrepresentable values or incomputable results. Similarly, values that fall within these limits are referred to as computable results or representable values. Incomputable results are those for which a valid mathematical result exists, but the result can not be represented due to natural limits of the processing system.
To account for natural limits on results for math functions, conventional systems often check an argument for invalid values. Such invalid values can be of several types, including those for which the result for the math function is undefined (such as division by zero). Certain math functions check in advance for incomputable results. For example, on a computer using the IBM hexadecimal floating point data representation, a routine that evaluates the exponential function exp(X) for a floating point argument X can check that the value of X does not exceed 174.673. If so, an error condition is signaled for an unrepresentable, invalid result. Other functions of a single argument such as exp(x), sinh(x), cosh(x), tan(x), arcsin(x), gamma(x), and the like typically check the argument value against one or two limit values (such as upper and lower bounds) to identify unrepresentable values.
Conventional math functions, however, typically fail to perform such checking for a computable result when the function involves a plurality of arguments. Conventionally, the overhead in determining whether the argument values will provide a computable result causes an unacceptable delay. Consequently, conventional math functions favor speed over reliability in evaluating functions that accept a plurality of arguments. The math functions presume that for the argument values provided the math function will return a representable result. Accordingly, the math function is evaluated using the argument values. The math function evaluation can consume considerable memory and processing resources. If the result of the math functions turns out to be unrepresentable, these resources are wasted.
Consequently, such function argument values are permitted to evaluate until the processing system detects that the result being computed is unrepresentable or noncomputable. Generally, a noncomputable result or an unrepresentable result is one that is a mathematically undefined result for the function, larger than the processing system is designed to represent, smaller than the processing system is designed to represent, or includes an imaginary portion such as with complex numbers when a real (non-complex) result is required.
FIG. 1 illustrates a conceptual representation 100 of a function f(x,y) that accepts a plurality of arguments (x,y) and maps values in a domain (x,y) 102 to a mathematical range f(x,y) 104 defined for the function f(x,y). The domain 102 and range 104 each comprises a number set of the same or different type. For example, the domain 102 may include whole numbers and the range 104 may include real numbers such as a decimal or other non-integer number.
The function f(x,y) 106 maps, or translates, a given x and a given y from the domain 102 to a proper result in the range 104. For example, suppose the domain 102 comprises whole numbers (integers as represented in the computer) and the function 106 is the mathematical power function f(x,y)=x^y. For most x and y values chosen in the domain 102, the function returns a valid computable result 108. If x=2 and y=3, f(x,y) returns the result 8. For certain values of x and y, the mathematical function may be undefined. So, if x=0 and y=0, the function 106, x^y, maps to a mathematically undefined result 110.
Other combinations of arguments x and y produce a result 112 that is either too large, or too small for the processing system evaluating the function 106 to represented. If the result or an intermediate result is too large, the condition is referred to as overflow. If the result or an intermediate result is too small, the condition is referred to as underflow.
Because the result is unrepresentable, the result is considered incomputable for the particular processing system. For example, suppose the processing system represents numbers as integers in a memory location having thirty-one data bits and one sign bit. Using the same function 106, x^y, if x=2 and y=31 the result 112 is larger than the largest positive integer that can be stored in a result memory location of the processing system.
FIG. 1 illustrates that this result 112 is mathematically valid, is within the mathematical range 104, but in this case is too large for the computer to represent using its standard hardware and architecture. Such a result 112 is considered outside the computable range 114 for the function 106. The computable range 114 represents a range of all computable results for a given function 106.
Results 112 outside of the computable range 114, including mathematically undefined results 110, are considered error conditions. Generally, the math function will signal this error condition. However, the math function typically does not identify the error condition until large amounts of time, memory, and processing power are expended.
Unfortunately, conventional math functions do not determine whether the given arguments will produce a computable result 108. One reason for this is the variation between arguments that can dramatically alter whether the result is within the computable range 114. For example, a given x and y value may produce a computable result 108. But changing one argument or the other can produce an incomputable result 110, 112. Keeping the same x value and using y′ produces an undefined result 110. Keeping the same y and using x′ produces incomputable result 112 due to overflow or underflow.
The interrelationships between the arguments and the function 106 and the affect of these relationships on the result falling within the range of computable results 114 make detecting such error conditions for values of a plurality of arguments very difficult. The range of computable results 114 varies depending on which values are provided for the arguments. Furthermore, the range of computable results 114 is shifted based on the value of a first argument in relation to the value of a second argument. Conventional math functions avoid such testing of arguments for a particular function because the overhead (which introduces a delay in function execution) in conducting such tests is expected to outweigh the benefit of preventing wasted computing resources.
From the foregoing discussion, it should be apparent that a need exists for an apparatus and system for efficient and reliable computation of results for mathematical functions. Beneficially, such an apparatus and system would operate accurately and very quickly in testing a plurality of math function arguments to determine whether present argument values produce a result within the range of computable results. Beneficially, the apparatus and system would incur minimal overhead in testing the arguments. In addition, the apparatus and system would prevent wasting computing resources evaluating a function for which the plurality of arguments would produce an incomputable result.